package com.example.tnot.Teacher.MinePart.InternalFragment.collection.adapter;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tnot.R;
import com.example.tnot.Teacher.MinePart.InternalFragment.collection.ItemBean.rv_collection;
import com.example.tnot.Util.ToastUtil;

import java.util.List;

public class rvCollectAdapter extends RecyclerView.Adapter<rvCollectAdapter.ViewHolder> {
    private  List<rv_collection> data;

    public rvCollectAdapter(List<rv_collection> data) {
        this.data = data;
    }

    @NonNull
    @Override
    public rvCollectAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_rv_home_resource, parent, false);
        return new rvCollectAdapter.ViewHolder(view);
    }


    public void onBindViewHolder(@NonNull rvCollectAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        holder.iv_ResImage.setImageResource(data.get(position).getImage());
        holder.tv_ResTitle.setText(data.get(position).getTitle());
        holder.tv_Resmessage.setText(data.get(position).getMessage());
        holder.tv_FirstLabel.setText(data.get(position).getFirstLabel());
        holder.tv_SecondLabel.setText(data.get(position).getSecondLabel());
        holder.tv_ThirdLabel.setText(data.get(position).getThirdLabel());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.showCustomToast(v.getContext(),"点击了"+data.get(position).getTitle());
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView iv_ResType,iv_ResImage;
        TextView tv_ResTitle,tv_Resmessage,tv_FirstLabel,tv_SecondLabel,tv_ThirdLabel;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            iv_ResType = itemView.findViewById(R.id.iv_ResType);
            iv_ResImage = itemView.findViewById(R.id.iv_ResImage);
            tv_ResTitle = itemView.findViewById(R.id.tv_ResTitle);
            tv_Resmessage = itemView.findViewById(R.id.tv_Resmessage);
            tv_FirstLabel = itemView.findViewById(R.id.tv_FirstLabel);
            tv_SecondLabel = itemView.findViewById(R.id.tv_SecondLabel);
            tv_ThirdLabel = itemView.findViewById(R.id.tv_ThirdLabel);
        }
    }
}
